import request from '@/router/axios'

export function roleList () {
  return request({
    url: '/api/admin/role/roleList',
    method: 'get'
  })
}

export function fetchList (query) {
  return request({
    url: '/api/manage/role/page',
    method: 'get',
    params: query
  })
}

export function roleGroup () {
  return request({
    url: '/api/manage/role/roleGroup',
    method: 'get'
  })
}

export function getObj (id) {
  return request({
    url: '/api/manage/role/' + id,
    method: 'get'
  })
}

export function addObj (obj) {
  return request({
    url: '/api/manage/role',
    method: 'post',
    data: obj
  })
}

export function putObj (obj) {
  return request({
    url: '/api/manage/role',
    method: 'put',
    data: obj
  })
}

export function delObj (id) {
  return request({
    url: '/api/manage/role/' + id,
    method: 'delete'
  })
}

export function permissionUpd (roleId, menuIds) {
  return request({
    url: '/api/manage/role/menu',
    method: 'put',
    data: {
      roleId: roleId,
      menuIds: menuIds
    }
  })
}

/**
 * 查询角色菜单列表
 * @param {number} roleId 角色id
 * @returns  菜单列表
 */
export function fetchRoleTree (roleId) {
  return request({
    url: '/api/manage/menu/roleTree/' + roleId,
    method: 'get'
  })
}
